<?php
namespace Deployer;

require 'recipe/laravel.php';

// Project name
set('application', 'canayiiy.mgtv100.com');
//set('application', 'admin.canayiiy.com');

// Project repository
set('repository', 'git@gitee.com:gyp719/canayiiy.git');

// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true);

// Shared files/dirs between deploys
add('shared_files', []);
add('shared_dirs', []);

// Writable dirs by web server
set('writable_dirs', []);
set('http_user', 'www-data');

// Hosts
host('mgtv100')
    ->stage('test')
    ->set('deploy_path', '/var/www/{{application}}');

host('canayiiy')
    ->stage('production')
    ->set('deploy_path', '/var/www/{{application}}');

// 定义一个上传 .env 文件的任务
desc('Upload .env file');
task('env:upload', function () {
    // 将本地的 .env 文件上传到代码目录的 .env
    upload('.env.example', '{{release_path}}/.env');
});

// 定义一个后置钩子，在 deploy:shared 之后执行 env:upload 任务
after('deploy:shared', 'env:upload');

// Tasks
desc('Restart PHP-FPM service');
task('php-fpm:restart', function () {
    run('sudo service php7.3-fpm restart');
//    run('sudo service php7.4-fpm restart');
});
after('deploy:symlink', 'php-fpm:restart');

task('build', function () {
    run('cd {{release_path}} && build');
//    run('cd {{release_path}} && chmod -R 777 storage');
});

// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

// Migrate database before symlink new release.

before('deploy:symlink', 'artisan:migrate');

